home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d875.lha / Blanker / Source.lha / Source / main.c < prev    next >
C/C++ Source or Header  |  1993-05-24  |  6KB  |  208 lines

  1. /** DoRev Header ** Do not edit! **
  2. *
  3. * Name             :  main.c
  4. * Copyright        :  Free Software
  5. * Creation date    :  12-May-93
  6. * Translator       :  SAS/C 6.2
  7. * Compiler opts.   :  See Makefile
  8. *
  9. * Date       Rev  Author               Comment
  10. * ---------  ---  -------------------  ----------------------------------------
  11. * 22-May-93    1  Michael D. Bayne     Removed mouse blanker
  12. * 12-May-93    0  Michael D. Bayne     Startup & utility code for Blanker
  13. *
  14. *** DoRev End **/
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <exec/ports.h>
  19. #include <dos/dos.h>
  20. #include <dos/dostags.h>
  21. #include <intuition/intuition.h>
  22. #include <graphics/displayinfo.h>
  23. #include <libraries/reqtools.h>
  24.  
  25. #include <clib/exec_protos.h>
  26. #include <clib/dos_protos.h>
  27. #include <clib/graphics_protos.h>
  28. #include <clib/alib_protos.h>
  29. #include <clib/utility_protos.h>
  30.  
  31. #include "defs.h"
  32. #include "Blanker.h"
  33.  
  34. /* Program revision tag. */
  35. STATIC const UBYTE VersTag[] = "\0$VER: "BVERSION" (5.22.93)";
  36.  
  37. /* Prototypes */
  38. LONG handleCxMess( void );
  39. LONG SetupCX( void );
  40. LONG UpdateCX( void );
  41. void ShutdownCX( void );
  42. void defBlanker( void );
  43.  
  44. void setPrefs( struct bPrefObject *, UBYTE );
  45. void loadPrefs( UBYTE *, UBYTE *, struct bPrefObject * );
  46. void savePrefs( UBYTE *, UBYTE *, struct bPrefObject * );
  47.  
  48. extern    ULONG        cxSigFlag, cxBlankFlag;
  49. extern    UBYTE        prefName[], prefDir[], modInfo[];
  50.     ULONG        blankSig, validPrefs;
  51. struct    ReqToolsBase    *ReqToolsBase;
  52. struct    Library        *CxBase, *IconBase;
  53. struct    Task        *Task = 0L, *bTask = 0L;
  54. struct    MsgPort        *blankerPort, *modulePort = 0L;
  55. struct    bMessage    bMsg;
  56. struct    bPrefObject    bPrefs = { 0x00008004, 4, 1800, "shift F2", "shift F1", FALSE, "Moire", "Blankers" };
  57. struct    Screen        *bScr;
  58. struct    NewBroker    nbBroker = { NB_VERSION, "Blanker", BVERSION, "A system friendly screen blanker",
  59.             NBU_UNIQUE|NBU_NOTIFY, COF_SHOW_HIDE, 0, 0, 0 };
  60.  
  61. int getBlanker( void )
  62. {
  63.     UBYTE    path[256];
  64.     struct    bMessage    *rMsg;
  65.     BPTR    checkExists;
  66.  
  67.     CopyMem( bPrefs.modDir, path, 108 );
  68.     if( !AddPart( path, bPrefs.modName, 256 )) return( 0 );
  69.     if( !modulePort ) {
  70.         if( checkExists = Open( path, MODE_OLDFILE ) ) {
  71.             Close( checkExists );
  72.             SystemTags( path, NP_FreeSeglist, TRUE, SYS_Asynch, TRUE,  SYS_Input,
  73.                 Open( "NIL:", MODE_OLDFILE ), SYS_Output, Open( "NIL:", MODE_OLDFILE ), TAG_END );
  74.             WaitPort( blankerPort );
  75.             rMsg = ( struct bMessage * )GetMsg( blankerPort );
  76.             modulePort = ( struct MsgPort * )rMsg->bMess.mn_ReplyPort;
  77.             bTask = ( struct Task * )rMsg->prefData;
  78.             ReplyMsg(( struct Message * )rMsg );
  79.             return( 1 );
  80.         } else return( 0 );
  81.     } else return( 1 );
  82. }
  83.  
  84. void getInfo( UBYTE *Info )
  85. {
  86.     if( getBlanker()) {
  87.         if( bPrefs.resident ) bMsg.bm_Type = BM_INFO;
  88.         else bMsg.bm_Type = BM_INFO|BM_QUIT;
  89.         bMsg.bm_Valid = validPrefs;
  90.         bMsg.prefData = bPrefs.prefData;
  91.         PutMsg( modulePort, ( struct Message * )( &bMsg ));
  92.         WaitPort( blankerPort );
  93.         GetMsg( blankerPort );
  94.         CopyMem( bMsg.prefData, Info, 64 );
  95.         if( !bPrefs.resident ) modulePort = 0l;
  96.     } else CopyMem( "Simple Blanker", Info, 15 );
  97. }
  98.  
  99. void callBlanker( void )
  100. {
  101.     if( getBlanker()) {
  102.         if( bPrefs.resident ) bMsg.bm_Type = BM_BLANK;
  103.         else bMsg.bm_Type = BM_BLANK|BM_QUIT;
  104.         bMsg.bm_Valid = validPrefs;
  105.         bMsg.sMod = bPrefs.sMod;
  106.         bMsg.sDep = bPrefs.sDep;
  107.         bMsg.prefData = bPrefs.prefData;
  108.         PutMsg( modulePort, ( struct Message * )( &bMsg ));
  109.         if( !bPrefs.resident ) modulePort = 0l;
  110.         WaitPort( blankerPort );
  111.         GetMsg( blankerPort );
  112.     } else defBlanker();
  113. }
  114.  
  115. LONG openMainWindow( void )
  116. {
  117.     if( !BlankerWnd ) {
  118.         if( SetupScreen()) return( 1 );
  119.         OpenBlankerWindow();
  120.         CloseDownScreen();
  121.     }
  122.     if( !BlankerWnd ) return( QUIT );
  123.     getInfo( modInfo );
  124.     setPrefs( &bPrefs, Blanker_CNT );
  125.     return( OK );
  126. }
  127.  
  128. void exitBlanker( LONG exitValue )
  129. {
  130.     if( modulePort ) {
  131.         bMsg.bm_Type = BM_UNLOAD;
  132.         PutMsg( modulePort, ( struct Message * )( &bMsg ));
  133.         WaitPort( blankerPort );
  134.         GetMsg( blankerPort );
  135.     }
  136.  
  137.     switch( exitValue ) {
  138.     case 0L:
  139.         CloseBlankerWindow();
  140.         DeletePort( blankerPort );
  141.     case 1L:
  142.         ShutdownCX();
  143.     case 2L:
  144.         FreeSignal( blankSig );
  145.     case 3L:
  146.         CloseLibrary(( struct Library * )ReqToolsBase );
  147.     case 4L:
  148.         CloseLibrary( IconBase );
  149.     case 5L:
  150.         CloseLibrary( CxBase );
  151.     case 6L:
  152.         CloseLibrary(( struct Library * )GfxBase );
  153.     case 7L:
  154.         CloseLibrary( GadToolsBase );
  155.     case 8L:
  156.         CloseLibrary(( struct Library * )IntuitionBase );
  157.     }
  158. }
  159.         
  160. void main( int argc, char *argv[] )
  161. {
  162.     ULONG    sigs;
  163.      LONG    retval = 1;
  164.     UBYTE    **ttypes;
  165.  
  166.     if(!( IntuitionBase = ( struct IntuitionBase * )OpenLibrary( "intuition.library", 37L ))) exitBlanker( 9L );
  167.     if(!( GfxBase = ( struct GfxBase * )OpenLibrary( "graphics.library", 37L ))) exitBlanker( 8L );
  168.     if(!( GadToolsBase = OpenLibrary( "gadtools.library", 37L ))) exitBlanker( 7L );
  169.     if(!( CxBase = OpenLibrary( "commodities.library", 37L ))) exitBlanker( 6L );
  170.     if(!( IconBase = OpenLibrary( "icon.library", 36L ))) exitBlanker( 5L );
  171.     if(!( ReqToolsBase = ( struct ReqToolsBase * )OpenLibrary( REQTOOLSNAME, REQTOOLSVERSION )))
  172.         exitBlanker( 4L );
  173.  
  174.     Task = FindTask( 0L );
  175.  
  176.     if( ttypes = ArgArrayInit( argc, argv )) {
  177.         nbBroker.nb_Pri  = ( BYTE )ArgInt( ttypes, "CX_PRIORITY", 0 );
  178.         if( !Stricmp( ArgString( ttypes, "CX_POPUP", "no" ), "yes" )) retval = 5;
  179.         ArgArrayDone();
  180.     } else nbBroker.nb_Pri = 0;
  181.  
  182.     if(( blankSig = ( ULONG )AllocSignal( -1L )) == -1 ) exitBlanker( 3L );
  183.     cxBlankFlag = 1L << blankSig;
  184.  
  185.     if(!( SetupCX())) exitBlanker( 2L );
  186.  
  187.     loadPrefs( "Blanker.prefs", "ENV:", &bPrefs );
  188.  
  189.     if(!( blankerPort = CreatePort( "BlankerCC", 0 ))) exitBlanker( 1L );
  190.     bMsg.bMess.mn_ReplyPort = blankerPort;
  191.     bMsg.bMess.mn_Length = sizeof( struct bMessage );
  192.  
  193.     UpdateCX();
  194.  
  195.     if( retval == 5 ) retval = openMainWindow();
  196.  
  197.     while( retval ) {
  198.         sigs = Wait( SIG_BREAK | cxSigFlag | cxBlankFlag | SIG_WINDOW );
  199.         if( sigs & SIG_WINDOW ) retval = HandleBlankerIDCMP();
  200.         if( sigs & cxSigFlag ) retval = handleCxMess();
  201.         if( sigs & cxBlankFlag ) callBlanker();
  202.         if( sigs & SIG_BREAK ) retval = 0L;
  203.         if( retval == CLOSEWIN ) CloseBlankerWindow();
  204.     }
  205.  
  206.     exitBlanker( 0L );
  207. }
  208.